using System;
using System.Collections.Generic;
using System.Text;
using ENTITIES;
using DAL;
using Utility;

namespace BUS
{
   public class CTDonHangBUS
    {
        public static void Insert(TBCTDonHang ctdh)
        {
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            ctdhDAL.Insert(ctdh);
        }
        public static void Update(TBCTDonHang ctdh)
        {
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            ctdhDAL.Update(ctdh);
        }
        public static void Delete(int iD)
        {
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            ctdhDAL.Delete(iD);
        }
        public static tbCTDonHangCollection Get(string where,
            int pageindex,
            int pagesize,
            string orderby,
            string orderdirection,
            out int total)
        {
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            return ctdhDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbCTDonHangCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            return ctdhDAL.Get(cri.Criter, 0, 0, tbCTDonHangColumns.MaCTDH.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static TBCTDonHang GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbCTDonHangColumns.MaCTDH.ToString(), Condition.EQUAL, iD);
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            tbCTDonHangCollection ctdhcollection = ctdhDAL.Get(cri.Criter,
                  0, 0, tbCTDonHangColumns.MaCTDH.ToString(), OrderDirection.ASC.ToString(), out total);
            if (ctdhcollection.Count > 0)
                return ctdhcollection[0];
            return null;
        }
        public static tbCTDonHangCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            return ctdhDAL.Get(cri.Criter, 1, number,
             tbCTDonHangColumns.MaCTDH.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbCTDonHangCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            CTDonHangDAL ctdhDAL = new CTDonHangDAL();
            return ctdhDAL.Get(cri.Criter, 1, number,
               tbCTDonHangColumns.MaCTDH.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}
    

